﻿using System.Collections.Generic;
using System.Windows;
using System;

using CRM.University.Core.Addins;

namespace CRM.University
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        AddinManager addManager;

        public MainWindow()
        {
            InitializeComponent();
            addManager = AddinManager.Instanse;
            addManager.LoadModules();
            
            int i = 0;
            foreach (var module in addManager.Modules)
            {
                var btn = new System.Windows.Controls.Button()
                {
                    Tag = i,
                    ToolTip = module.Name,
                    Content = new System.Windows.Controls.Image()
                    {
                        Source = module.Source,
                        Width = 25,
                        Height = 25
                    },
                    Background = System.Windows.Media.Brushes.Transparent,
                    BorderBrush = System.Windows.Media.Brushes.Transparent
                };
                btn.Click += new RoutedEventHandler(btn_Click);
                modulesDockPanel.Children.Add(btn);

                i++;
            }
        }

        void btn_Click(object sender, RoutedEventArgs e)
        {
            holderPlace.Children.Clear();

            holderPlace.Children.Add(addManager.Modules[(int)((System.Windows.Controls.Button)sender).Tag].Control);
        }
    }
}
